package pl.un4giv3n.mightvsmagic.admin.action;

import javax.persistence.EntityManager;

import pl.un4giv3n.mightvsmagic.action.PersistenceAction;
import pl.un4giv3n.mightvsmagic.entity.ItemTemplate;
import pl.un4giv3n.mightvsmagic.entity.ItemType;
import pl.un4giv3n.mightvsmagic.entity.User;
import pl.un4giv3n.mightvsmagic.entity.UserType;

/**
 * @author andrzejewskia
 * this action adds new items to the bazar
 * this action should be performed by admin ONLY
 */
public class EditItemPageAction extends PersistenceAction {

	private static final long serialVersionUID = 1L;
	
	private Long itemId;
	
	/**
	 * session user
	 */
	private User user;

	private ItemTemplate template;

	/* (non-Javadoc)
	 * @see pl.un4giv3n.mightvsmagic.action.PersistenceAction#execute()
	 */
	@Override
	public String execute() {
		EntityManager entityManager = getEntityManager();
		user = getSessionUser(entityManager);
		if (user == null || user.getUserType() != UserType.ADMIN) {
			addActionError("Zaloguj się");
			entityManager.close();
			return LOGIN;
		}
		if(itemId != null){
			template = entityManager.find(ItemTemplate.class, itemId);
		}
		return SUCCESS;
	}

	public String getName() {
		return template == null ? "" : template.getName();
	}

	public ItemType getType() {
		return template == null ? null : template.getType();
	}

	public String getImgUrl() {
		return template == null ? "" : template.getImgUrl();
	}

	public String getMinDef() {
		return template == null ? "" : template.getMinDef()+"";
	}

	public String getMaxDef() {
		return template == null ? "" : template.getMaxDef()+"";
	}

	public String getMinDmg() {
		return template == null ? "" : template.getMinDmg()+"";
	}

	public String getMaxDmg() {
		return template == null ? "" : template.getMaxDmg()+"";
	}

	public String getPrice() {
		return template == null ? "" : template.getPrice()+"";
	}
	public String getPremiumPrice() {
		return template == null ? "" : template.getPremiumPrice()+"";
	}

	public String getStrengthMod() {
		return template == null ? "" : template.getStrenghtModifier()+"";
	}

	public String getStaminaMod() {
		return template == null ? "" : template.getStaminaModifier()+"";
	}

	public String getManaMod() {
		return template == null ? "" : template.getManaModifier()+"";
	}

	public String getAttackMod() {
		return template == null ? "" : template.getAttackModifier()+"";
	}

	public String getDefenceMod() {
		return template == null ? "" : template.getParryModifier()+"";
	}
	public String getSpeedMod() {
		return template == null ? "" : template.getSpeedModifier()+"";
	}

	public String getStrengthReq() {
		return template == null ? "" : template.getStrenghtReq()+"";
	}

	public String getStaminaReq() {
		return template == null ? "" : template.getStaminaReq()+"";
	}

	public String getManaReq() {
		return template == null ? "" : template.getManaReq()+"";
	}

	public String getAttackReq() {
		return template == null ? "" : template.getAttackReq()+"";
	}

	public String getDefenceReq() {
		return template == null ? "" : template.getParryReq()+"";
	}

	public String getRequiredFightExp() {
		return template == null ? "" : template.getRequiredFightExp()+"";
	}

	public String getRequiredMagicExp() {
		return template == null ? "" : template.getRequiredMagicExp()+"";
	}
	public String getRequiredAnyExp() {
		return template == null ? "" : template.getRequiredAnyExp()+"";
	}

	public Long getItemId() {
		return itemId;
	}

	public void setItemId(Long itemId) {
		this.itemId = itemId;
	}
	
}
